package com.puman.dao.impl;

import java.util.List;
import java.util.Map;

import org.hibernate.Query;
import org.hibernate.criterion.DetachedCriteria;
import org.springframework.stereotype.Repository;

import com.core.BaseDaoImpl;
import com.core.Pager;
import com.puman.bean.Staff;
import com.puman.dao.StaffDao;

@Repository("staffDao")
public class StaffDaoImpl extends BaseDaoImpl<Staff> implements StaffDao {

	public List<Staff> getList(Integer supplier_id){
		String hql = "select s.id,s.name,s.gasstation_id,g.name as GASSTATION_NAME,s.emp_no,s.mobile,s.account,"+
			"s.password,s.icon_url,s.create_date,s.create_user_id,s.create_user_name,"+
			"s.modify_date,s.modify_user_id,s.modify_user_name "+ 
			" from m_gasstation_staff s left join m_Gasstation g on s.GASSTATION_ID = g.ID "+
			" where 1=1 and s.GASSTATION_ID in (select ID from m_Gasstation where SUPPLIER_ID = "+ supplier_id + ") order by s.modify_date desc";
		List<Staff> list = getSession().createSQLQuery(hql).addEntity(Staff.class).list();
		return list;
	}

	@Override
	public List<Staff> getListLike(Integer supplier_id, String name) {
		String hql = "select s.id,s.name,s.gasstation_id,g.name as GASSTATION_NAME,s.emp_no,s.mobile,s.account,"+
				"s.password,s.icon_url,s.create_date,s.create_user_id,s.create_user_name,"+
				"s.modify_date,s.modify_user_id,s.modify_user_name "+ 
				" from m_gasstation_staff s left join m_Gasstation g on s.GASSTATION_ID = g.ID "+
				" where 1=1 and s.GASSTATION_ID in (select ID from m_Gasstation where SUPPLIER_ID = "+ supplier_id + ")"+
				" and s.name like '%"+name+"%' order by s.modify_date desc";
			List<Staff> list = getSession().createSQLQuery(hql).addEntity(Staff.class).list();
			return list;
	}
}
